SET(CMAKE_INCLUDE_CURRENT_DIR ON)

SET(SOURCES
Awesomium.rc
resource.h
msvc/stdint.h
api/WebCore.h
api/WebView.h
api/WebViewEvent.h
api/WebViewListener.h
javascript/ClientObject.cpp
javascript/ClientObject.h
javascript/JSValue.cpp
javascript/JSValue.h
javascript/NPApi.cpp
javascript/NPApi.h
utilities/PlatformUtils.cpp
utilities/PlatformUtils.h
webcore/WebCore.cpp
webcore/WebCoreProxy.cpp
webcore/WebCoreProxy.h
webcore/WebkitGlue.cpp
webview/NavigationController.h
webview/PopupWidget.cpp
webview/PopupWidget.h
webview/RenderBuffer.cpp
webview/RenderBuffer.h
webview/WebView.cpp
webview/WebViewEvent.cpp
webview/WebViewProxy.cpp
webview/WebViewProxy.h
webview/WindowlessPlugin.h
)

IF (APPLE)
LIST(APPEND SOURCES
mac/InitMacApplication.mm
)
ENDIF()

# TODO should have a FindChromium.cmake file
SET(CHROMIUM_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../Chromium/src")

SET(CHROMIUM_SOURCES
${CHROMIUM_ROOT}/webkit/tools/test_shell/simple_appcache_system.cc
${CHROMIUM_ROOT}/webkit/tools/test_shell/simple_resource_loader_bridge.cc
${CHROMIUM_ROOT}/webkit/tools/test_shell/simple_socket_stream_bridge.cc
${CHROMIUM_ROOT}/webkit/tools/test_shell/test_shell_request_context.cc
)

INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/skia/include/config")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/skia/include/core")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/skia/ext")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/WebKit/JavaScriptCore")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/npapi")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/WebKit/WebKit/chromium/public")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/WebKit/WebKit/chromium/public/win")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/WebKit/WebCore/platform/text")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/WebKit/WebCore/history")
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/icu/public/common")

IF (WIN32)
INCLUDE_DIRECTORIES("${CHROMIUM_ROOT}/third_party/platformsdk_win2008_6_1/files/Include")
LINK_DIRECTORIES("${CHROMIUM_ROOT}/third_party/platformsdk_win2008_6_1/files/Lib")
ENDIF()

IF (MSVC)
LINK_DIRECTORIES("${CHROMIUM_ROOT}/build/${CMAKE_CFG_INTDIR}/lib")
ENDIF()
IF (APPLE)
# TODO configure this
#SET(CHROMIUM_LIBS_PATH "${CHROMIUM_ROOT}/xcodebuild/Release")
SET(CHROMIUM_LIBS_PATH "${CHROMIUM_ROOT}/xcodebuild/Debug")
#LINK_DIRECTORIES("${CHROMIUM_LIBS_PATH}")
ENDIF()

ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-DOSM_NONCLIENT_BUILD)
ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN)
ADD_DEFINITIONS(-DNOMINMAX)
ADD_DEFINITIONS(-DWEBKIT_USING_SKIA)
ADD_DEFINITIONS(-DSK_IGNORE_STDINT_DOT_H)
ADD_DEFINITIONS(-DU_HAVE_INT32_T=1)
ADD_DEFINITIONS(-DU_HAVE_UINT32_T=1)
ADD_DEFINITIONS(-D_WIN32_WINNT=0x0600)
ADD_DEFINITIONS(-DWINVER=0x0600)
ADD_DEFINITIONS(-D_SECURE_ATL)

IF(MSVC)
# remove support for Exception handling
STRING(REPLACE "/GX" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT ${CMAKE_CXX_FLAGS_INIT})
STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_DEBUG_INIT ${CMAKE_CXX_FLAGS_DEBUG_INIT})
ADD_DEFINITIONS(-D_HAS_EXCEPTIONS=0)
ENDIF(MSVC) 

SOURCE_GROUP( "_chromium" FILES ${CHROMIUM_SOURCES} )

ADD_LIBRARY(Awesomium SHARED ${SOURCES} ${CHROMIUM_SOURCES})

IF (MSVC)
SET_TARGET_PROPERTIES(Awesomium PROPERTIES LINK_FLAGS /OPT:REF /OPT:ICF /OPT:NOWIN98)
ENDIF()

SET_TARGET_PROPERTIES(Awesomium PROPERTIES LINK_INTERFACE_LIBRARIES "")

# ffmpeg

IF (MSVC)
TARGET_LINK_LIBRARIES(Awesomium 
	avcodec-52
	avformat-52
	avutil-50
)
ENDIF()

IF (MSVC)
TARGET_LINK_LIBRARIES(Awesomium 
	app_base
	appcache
	base
	base_i18n
	breakpad_handler
	common
	common_constants
	database
	default_plugin
	Glue
	googleurl
	gtest
	icui18n
	icuuc
	libjpeg
	libpng
	libxslt
	libxml2
	media
	modp_b64
	net
	net_base
	ots
	pcre
	sdch
	skia
	sqlite3
	v8_base
	v8_snapshot
	WebCore
	webcore_bindings
	WebKit
	WTF
	zlib
	libbzip2
	skia_sse2
)
ENDIF()

SET(CHROMIUM_LIBS 
	app_base
	appcache
	base
	base_i18n
	chrome_bz2
	chrome_zlib
	common
	common_constants
	database
	event
	gfx
	glue
	googleurl
	gtest
	ffmpeg
	icudata
	icui18n
	icuuc
	il
	jpeg
	png
	xslt
	xml2
	media
	modp_b64
	net
	net_base
	omx_wrapper
	ots
	pcre
	platform
	sdch
	skia
	skia_opts
	sqlite3
	v8_base
	v8_snapshot
	webcore
	webcore_bindings
	webkit
	webkit_support
	webkit_system_interface
	WebKitSystemInterfaceLeopardPrivateExtern
	wtf
	skia
)
FOREACH(CHROMIUM_LIB_NAME ${CHROMIUM_LIBS})
	TARGET_LINK_LIBRARIES(Awesomium "${CHROMIUM_LIBS_PATH}/lib${CHROMIUM_LIB_NAME}.a")
ENDFOREACH()

# system libraries

IF (MSVC)
TARGET_LINK_LIBRARIES(Awesomium 
	wininet
	version
	msimg32
	ws2_32
	usp10
	psapi
	dbghelp
	comctl32
	winmm
	urlmon
)
ENDIF()

IF(APPLE)
  # Locate Frameworks
  FIND_LIBRARY(F_APPKIT_FRAMEWORK AppKit REQUIRED)
  FIND_LIBRARY(F_CARBON_FRAMEWORK Carbon REQUIRED)
  FIND_LIBRARY(F_COREGRAPHICS_FRAMEWORK ApplicationServices REQUIRED)
  FIND_LIBRARY(F_CORESERVICES_FRAMEWORK CoreServices REQUIRED)
  FIND_LIBRARY(F_FOUNDATION_FRAMEWORK Foundation REQUIRED)
  FIND_LIBRARY(F_IOKIT_FRAMEWORK IOKit REQUIRED)
  FIND_LIBRARY(F_SECURITY_FRAMEWORK Security REQUIRED)
  FIND_LIBRARY(F_SYSTEMCONFIG_FRAMEWORK SystemConfiguration REQUIRED)

  TARGET_LINK_LIBRARIES(Awesomium ${F_APPKIT_FRAMEWORK})
  TARGET_LINK_LIBRARIES(Awesomium ${F_CARBON_FRAMEWORK})
  TARGET_LINK_LIBRARIES(Awesomium ${F_COREGRAPHICS_FRAMEWORK})
  TARGET_LINK_LIBRARIES(Awesomium ${F_CORESERVICES_FRAMEWORK})
  TARGET_LINK_LIBRARIES(Awesomium ${F_FOUNDATION_FRAMEWORK})
  TARGET_LINK_LIBRARIES(Awesomium ${F_IOKIT_FRAMEWORK})
  TARGET_LINK_LIBRARIES(Awesomium ${F_SECURITY_FRAMEWORK})
  TARGET_LINK_LIBRARIES(Awesomium ${F_SYSTEMCONFIG_FRAMEWORK})

  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fno-rtti")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")

  SET(CMAKE_SHARED_LINKER_FLAGS "-t") # ld diagnostics

ENDIF()

#SET(CMAKE_EXE_LINKER_FLAGS "-framework ApplicationServices CoreGraphics Foundation")

# prevent propagation of static libraries used to build Awesomium
#SET_PROPERTY(TARGET Awesomium PROPERTY LINK_INTERFACE_LIBRARIES "")
